package sdufe.lele.service;


import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import sdufe.lele.dao.FinancialMapper;
import sdufe.lele.dao.UserinfoMapper;
import sdufe.lele.model.Financial2user;
import sdufe.lele.model.Userinfo;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Repository
public class BalanceService {

    @Resource
    private FinancialMapper financialMapper;

    @Resource
    private UserinfoMapper userinfoMapper;

    @Transactional
    public void updateBalance(Financial2user financial2user) {
        financialMapper.insert_product(financial2user);
        Userinfo userinfo = userinfoMapper.selectByPhone(financial2user.getUserphone());
        BigDecimal newBalance = financial2user.getBalance().add(userinfo.getBalance());
        userinfoMapper.updateBalance(newBalance, financial2user.getUserphone());


    }
}
